package bTree.LeetCode;

public class 回文子串 {
    public int countSubstrings(String s) {
        int result = 0;
        int length = s.length();
        boolean[][] dp = new boolean[length + 1][length + 1];
        for (int i = length; i > 0; i--) {
            for (int j = i; j <= length; j++) {
                if (s.charAt(i - 1) == s.charAt(j - 1)) {
                    if (j - i <= 1) {
                        dp[i][j] = true;
                        result++;
                    } else {
                        if (dp[i + 1][j - 1] == true) {
                            dp[i][j] = true;
                            result++;
                        }
                    }
                }
            }
        }
        return result;
    }
}